﻿using B.S.Ingredients.APIRead.Application.Command.EnterCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.EnterCommandHandler
{
    public class EnterQueryCommandHandler : IRequestHandler<EnterQueryCommand, APIResult<EnterClass>>
    {
        public EnterQueryCommandHandler(IBaseRepository<EnterClass> enterRepository)
        {
            EnterRepository = enterRepository;
        }

        public IBaseRepository<EnterClass> EnterRepository { get; }

        public async Task<APIResult<EnterClass>> Handle(EnterQueryCommand request, CancellationToken cancellationToken)
        {
            var path = EnterRepository.GetAll().FirstOrDefault(a => a.Productuin == request.Productuin);
            return new APIResult<EnterClass>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
